package cn.doitedu.kylin.jdbc;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class Demo {
    public static void main(String[] args) throws Exception {

        Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();

        Properties prop = new Properties();
        prop.setProperty("user", "ADMIN");
        prop.setProperty("password", "KYLIN");

        // 后面的“库”在这里指的“工程名” project_name
        Connection conn = driver.connect("jdbc:kylin://doitedu01:7070/doit17", prop);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select province, page_id, count(1) as session_cnt, count(distinct guid) as uv_cnt, sum(duration) as duration  from kylin.dws_pv_se group by province,page_id");
        while(rs.next()){
            String province = rs.getString(1);
            String page_id = rs.getString(2);
            long session_cnt = rs.getLong(3);
            long uv_cnt = rs.getLong(4);
            long duration = rs.getLong(5);

            System.out.println(province + "," + page_id + "," + session_cnt + "," + uv_cnt + "," + duration);
        }

        rs.close();
        stmt.close();
        conn.close();

    }
}
